package com.tourism.website.collection.controller;


import com.tourismwebsite.dto.PageDTO;
import com.tourism.website.apis.CollectionApis;
import com.tourism.website.collection.service.IFavoriteService;
import com.tourismwebsite.collection.dto.FavoriteDTO;
import com.tourismwebsite.collection.query.FavoriteQuery;
import com.tourismwebsite.vo.JsonVO;
import io.swagger.annotations.*;
import org.apache.ibatis.annotations.Delete;
import org.apache.tomcat.Jar;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LYC
 * @since 2024-06-06
 */
//TODO 12.控制器
@RestController
@RequestMapping("/collection")
@Validated
@Api(tags = "收藏夹管理")
public class FavoriteController implements CollectionApis {
    @Resource
    IFavoriteService favoriteService;
//    查询收藏列表
//    @GetMapping("query-favorite-page")
//    @Override
//    public JsonVO<PageDTO<FavoriteDTO>> queryFavoriteList(@Validated FavoriteQuery favoriteQuery) {
//        return JsonVO.success(favoriteService.queryFavoriteList(favoriteQuery));
//    }
    @Override
    public JsonVO<List<FavoriteDTO>> queryFavorite(Integer favoriteId) {
        List<FavoriteDTO> favoriteDTOS=favoriteService.queryFavorite(favoriteId);
        if(!favoriteDTOS.isEmpty())
            return JsonVO.success(favoriteDTOS);
        return JsonVO.create(null,10000,"收藏夹为空");
    }
    /**
     * 参数校验favoriteId不可为空
     * @param favoriteId
     * @return
     */
    @GetMapping("/query-favorite-table")
    @ApiOperation(value = "查询收藏夹列表")
    @ApiImplicitParam(name="favoriteId",value = "收藏夹ID",paramType="query")
    public JsonVO<List<FavoriteDTO>> queryFavoriteValidated(
            @NotNull(message = "收藏夹ID不可为空") Integer favoriteId){
     return queryFavorite(favoriteId);
    }


    @PostMapping("/save-favorite")
    @ApiOperation(value = "添加收藏夹")
    @Override
    public JsonVO<Boolean> saveFavorite(@Validated FavoriteQuery favoriteQuery) {
        Boolean result=favoriteService.saveFavorite(favoriteQuery);
        if(result)
        return JsonVO.success(result);
        else return JsonVO.fail(null);
    }
    @DeleteMapping("/delete-favorite")
    @ApiOperation(value = "删除收藏夹(批量)")
    @Override
    public JsonVO<Boolean> deleteFavorite(@Validated FavoriteQuery favoriteQuery) {
        Boolean result=favoriteService.deleteBatchFavorite(favoriteQuery);
        if(result)
        return JsonVO.success(result);
        else return JsonVO.fail(null);
    }

}

